package cc.yiueil.modeler.controller;

import org.activiti.engine.ActivitiException;
import org.apache.commons.io.IOUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.InputStream;


@RestController
@RequestMapping("/act-model")
public class ActModelController {

    @GetMapping(value = "/editor/i18n/{fileName}")
    public String getI18nJson(@PathVariable String fileName) {
        InputStream stream = this.getClass().getResourceAsStream("/i18n/" + fileName);
        if (stream == null) {
            throw new ActivitiException("Error while loading i18n file: ");
        }
        try {
            return IOUtils.toString(stream, "utf-8");
        } catch (Exception e) {
            throw new ActivitiException("Error while loading i18n file: ", e);
        }
    }

}
